/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crm.salesOrderProcessing.managedbean;

import java.io.IOException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import crm.salesOrderProcessing.entity.SalesOrderEntity;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import scm.inventoryControl.session.stateless.InventoryControlSessionBean;

/**
 *
 * @author xhx
 */
@ManagedBean(name="salesOrderCreationResultManagedBean")
@ViewScoped
public class salesOrderCreationResultManagedBean {
private SalesOrderEntity salesOrder;
private String displayContent;
private String lastPage ="";
private boolean draft;
private boolean verify;
private boolean creditCheck;
private boolean atpCheck;
private boolean largeOrder;
private boolean largeOrderApprove;
@EJB
InventoryControlSessionBean inventoryControlSessionBean;
    /** Creates a new instance of salesOrderCreationResultManagedBean */
    public salesOrderCreationResultManagedBean() {
    }
       
   
    
        public void initView(PhaseEvent event) {
        if (getSalesOrder() == null) { 
            setSalesOrder((SalesOrderEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("salesOrder"));
            
        }   
           lastPage = FacesContext.getCurrentInstance().getExternalContext().getFlash().get("lastURL").toString(); 
           if(lastPage.contains("createSalesOrder"))
               displayContent = "The Sales Order is Successfully Created";
           if(lastPage.contains("saveDraft"))
               displayContent = "Draft is saved";
           if(lastPage.contains("amendSalesOrder"))
               displayContent = "The Sales Order has been Successfully Amended";
           if(lastPage.contains("verifySalesOrder"))
               displayContent = "The Sales Order is Verified and thus is Successfully Created";
           if(salesOrder.getStatusId()==50){
               draft=true;
           }
           if(salesOrder.getStatusId()==100){
               verify=true;
               largeOrder = true;
           }
           if(salesOrder.getStatusId()>=200){
               verify=true;
               largeOrderApprove = true;
           }
           if(salesOrder.getStatusId()==300){
               verify=true;
               creditCheck =true;
           }
           if(salesOrder.getStatusId()==400){
               verify=true;
               creditCheck =true;
               atpCheck = true;
           }
        
    }

        public void viewDetail() throws IOException{
//    FacesContext.getCurrentInstance().getExternalContext().getFlash().put("lastURL", "viewAllPurchaseOrder.xhtml");
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("salesOrder", salesOrder);
        FacesContext.getCurrentInstance().getExternalContext().redirect("displaySalesOrder.xhtml");        
        }

    public SalesOrderEntity getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(SalesOrderEntity salesOrder) {
        this.salesOrder = salesOrder;
    }

    public String getDisplayContent() {
        return displayContent;
    }

    public void setDisplayContent(String displayContent) {
        this.displayContent = displayContent;
    }

    public String getLastPage() {
        return lastPage;
    }

    public void setLastPage(String lastPage) {
        this.lastPage = lastPage;
    }

    public boolean isDraft() {
        return draft;
    }

    public void setDraft(boolean draft) {
        this.draft = draft;
    }

    public boolean isVerify() {
        return verify;
    }

    public void setVerify(boolean verify) {
        this.verify = verify;
    }

    public boolean isCreditCheck() {
        return creditCheck;
    }

    public void setCreditCheck(boolean creditCheck) {
        this.creditCheck = creditCheck;
    }

    public boolean isAtpCheck() {
        return atpCheck;
    }

    public void setAtpCheck(boolean atpCheck) {
        this.atpCheck = atpCheck;
    }

    public boolean isLargeOrder() {
        return largeOrder;
    }

    public void setLargeOrder(boolean largeOrder) {
        this.largeOrder = largeOrder;
    }

    public boolean isLargeOrderApprove() {
        return largeOrderApprove;
    }

    public void setLargeOrderApprove(boolean largeOrderApprove) {
        this.largeOrderApprove = largeOrderApprove;
    }
}
